package org.tc.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.tc.bean.Item;
import org.tc.bean.ItemDesc;
import org.tc.common.Result;
import org.tc.common.ResultUtils;
import org.tc.service.ItemDescService;
import org.tc.service.ItemService;
import org.tc.utils.JsonUtils;

/**
 * Created by zxd on 2018/1/29.
 */
@RequestMapping("/api/item")
@Controller
public class ItemRpcController {

    private Logger LOGGER= LoggerFactory.getLogger(ItemRpcController.class);
    @Autowired
    private ItemService itemService;

    @Autowired
    private ItemDescService itemDescService;

    @RequestMapping(value = "{itemId}")
    @ResponseBody
    public Result<Item> queryItem(@PathVariable("itemId") Long itemId){
        LOGGER.info("请求的商品id是{}.",itemId);
        Item item = itemService.queryById(itemId);
        LOGGER.debug("查询的商品的信息 {}", JsonUtils.objectToJson(item));
        return ResultUtils.buildSuccess(item);
    }


    @RequestMapping(value = "/desc/{itemId}")
    @ResponseBody
    public Result<ItemDesc> queryItemDesc(@PathVariable("itemId") Long itemId){
        LOGGER.info("请求的商品id是{}.",itemId);
        ItemDesc itemDesc = itemDescService.queryById(itemId);
        LOGGER.debug("查询的商品的信息 {}", JsonUtils.objectToJson(itemDesc));
        return ResultUtils.buildSuccess(itemDesc);
    }








}
